package com.hualude.roadsign.repository;

import com.hualude.roadsign.dto.PortDto;
import com.hualude.roadsign.model.PortEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

/**
 * Created by xu_jiaHui on 2017/10/13.
 */
public interface PortRepository extends CrudRepository<PortEntity,Long> {

    @Query(value = "select new com.hualude.roadsign.dto.PortDto(portId,portNum,portState," +
            "portMeterValue,portMeterMin,portMeterMax,createTime,updateTime) from PortEntity where deviceId=?1")
    public List<PortDto> getPortById(String deviceId)throws Exception;

    @Modifying
    @Query(value = "delete from PortEntity where portId=?1")
    public Integer deletePortById(Integer portId)throws Exception;

    @Modifying
    @Query(value = "update PortEntity set portNum=?2,portState=?3,portMeterValue=?4,portMeterMin=?5,portMeterMax=?6,createTime=?7,updateTime=?8 where portId=?1")
    public Integer updatePort(Integer portId, Integer portNum, Integer portState, Double portMeterValue, Double portMeterMin, Double portMeterMax, String createTime, String updateTime);
}
